import { Body, Controller, Post, Req } from '@nestjs/common';
import { DeliveryAddressService } from "./delivery-address.service";
import { DeliveryAddressEntity } from "./delivery-address.entity";
import { ApiBasicAuth, ApiExtraModels, ApiOperation, ApiTags } from "@nestjs/swagger";
import { GetCurrentUser } from 'src/utils/common.utils';
import { Request } from 'express';
import { IdVo } from 'src/vo/common/id.vo';
import { ApiResult } from 'src/decorators/api-result.decorator';
import { ResultVo } from 'src/vo/common/result.vo';
import {OrderDetailVo} from "../../vo/order/order-detail.vo";


@ApiExtraModels(DeliveryAddressEntity, ResultVo)
@Controller('deliveryAddress')
@ApiTags('收货地址')
@ApiBasicAuth("token")
export class DeliveryAddressController {
    constructor(private readonly deliveryAddressService: DeliveryAddressService) { }

    @Post("queryAll")
    @ApiResult(DeliveryAddressEntity, true)
    @ApiOperation({ summary: '查询所有数据' })
    async queryAll(@Req() request: Request) {
        const userInfo = GetCurrentUser(request);
        return await this.deliveryAddressService.queryAll(userInfo.id);
    }

    @Post("queryOne")
    @ApiResult(DeliveryAddressEntity)
    @ApiOperation({ summary: '根据id查询详情' })
    async queryOne(@Body() data: IdVo) {
        return await this.deliveryAddressService.queryOne(data.id);
    }

    @Post("add")
    @ApiResult()
    @ApiOperation({ summary: '新增' })
    async add(@Body() data: DeliveryAddressEntity) {
        return await this.deliveryAddressService.add(data)
    }

    @Post("edit")
    @ApiResult()
    @ApiOperation({ summary: '编辑' })
    async edit(@Body() data: DeliveryAddressEntity) {
        return await this.deliveryAddressService.edit(data)
    }

    @Post("delete")
    @ApiResult()
    @ApiOperation({ summary: '删除' })
    async delete(@Body() data: IdVo) {
        return await this.deliveryAddressService.delete(data.id)
    }
}
